package com.lihua.newideas.mapper;

import com.lihua.newideas.pojo.Comment;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/*
 * 文章评论
 * */
@Mapper
@Repository
public interface CommentMapper {
    //插入一条评论
    @Insert("insert into comment(article_id,user_name,comment) values(#{articleId},#{userName},#{comment})")
    void insertComment(Comment comment);
    //根据文章id查询评论
    @Select("select * from comment where article_id = #{articleId} order by id desc")
    List<Comment> queryCommentByArticleId(@Param("articleId") long articleId);
    //根据id删除评论
    @Delete("delete from comment where id = #{id}")
    void deleteCommentById(@Param("id") long id);

    //根据文章和用户名判断是否评论过
    @Select("select * from comment where article_id = #{articleId} and user_name = #{userName}")
    Comment queryCommentByArticleIdAndUserName( @Param("articleId") long articleId ,@Param("userName") String userName);
}
